<template>
    <div class="dialog">
        <div class="background" @click="giveUp()"></div>
        <div class="dialogdiv">
            <label>动态审核</label>
            <div class="message">
                <div class="perdiv">
                    <label><strong>用户姓名&nbsp;&nbsp;</strong></label>
                    <input type="text" ref="nickname" :value="user.nickname">
                </div>
                <div class="perdiv">
                    <label><strong>用户状态&nbsp;&nbsp;</strong></label>
                    <select ref="state" v-model="user.state">
                        <option value="正常">正常</option>
                        <option value="封禁">封禁</option>
                        <option value="注销">注销</option>
                    </select>
                </div>
                <div class="perdiv">
                    <label><strong>用户性别&nbsp;&nbsp;</strong></label>
                    <select ref="sex" v-model="user.sex">
                        <option value="男">男</option>
                        <option value="女">女</option>
                    </select>
                </div>
                <div class="perdiv">
                    <label><strong>所属学校&nbsp;&nbsp;</strong></label>
                    <input ref="school" type="text" :value="user.school">
                </div>
                <div class="perdiv">
                    <label><strong>邮箱地址&nbsp;&nbsp;</strong></label>
                    <input ref="username" type="text" :value="user.username">
                </div>
                <div class="perdiv">
                    <label><strong>用户电话&nbsp;&nbsp;</strong></label>
                    <input ref="telephone" type="text" :value="user.telephone">
                </div>
                <div class="photo">
                    <div class="photoText">
                        <label><strong>用户头像</strong></label>
                    </div>
                    <div class="pictures">
                        <span>
                            <img ref="img" :src="user.img">
                        </span>
                    </div>
                </div>
                <div class="perdiv buttons">
                    <button class="yesbtn" @click="examine()">修改</button>
                    <button class="giveup" @click="giveUp()">取消</button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    name: 'UserDialog',
    data(){
        return{

        }
    },
    computed:{
        user(){
            return this.$store.state.userAdmin
        }
    },
    methods:{
        giveUp(){
            this.$store.state.dialog = 0
        },
        examine(){
            axios.post(`http://123.57.251.41:8080/admin-user/modifyUserInfo?username=${this.$refs.username.value}&sex=${this.$refs.sex.value}&nickname=${this.$refs.nickname.value}&img=${this.$refs.img.src}&state=${this.$refs.state.value}&school=${this.$refs.school.value}&roles=${this.user.roles}&userId=${this.user.userId}&telephone=${this.$refs.telephone.value}`,{headers:{'Authentication-Token': JSON.parse(sessionStorage.getItem("token"))}}).then(
                response =>{
                    alert('修改成功')
                    // console.log(this.user)
                    console.log(response.data.data)
                    this.$store.state.dialog = 0
                },
                error =>{
                    alert("修改失败",console.log(error))
                    this.$store.state.dialog = 0
                }
            )
            // axios({
            //     url: `http://123.57.251.41:8080/admin-user/modifyUserInfo`,
            //     params:{
            //         username=this.$refs.username.value,
            //         sex=this.$refs.sex.value,
            //         nickname=this.$refs.nickname.value,
            //         img=this.$refs.img.src,
            //         state=this.$refs.state.value,
            //         school=this.$refs.school.value,
            //         roles=this.user.roles,
            //         userId=this.user.userId,
            //         telephone=this.$refs.telephone.value,
            //     },
            //     headers: {
            //         'Content-Type': 'multipart/form-data'
            //     },
            //     method:'post'
            // }).then(function(data){
            //     console.log(data)
            // }).catch(function (error){
            //     console.log(error)
            // })
        }
    },
}
</script>

<style>
</style>